<?php


namespace App\Http\Controllers\Admin;


use App\Http\Requests\CoinsApplicationCreateRequest;
use App\Http\Requests\CoinsApplicationRequest;
use App\Http\Requests\CoinsApplicationUpdateRuleRequest;
use App\Http\Requests\CoinsApplicationUpdateTypeRequest;
use App\Http\Requests\CoinsApplicationUpdateDeductRequest;
use App\Http\Requests\CoinsApplicationUpdateManualRequest;
use App\Http\Requests\CoinsApplicationUpdateRequest;
use App\Http\Resources\HomeResource;
use App\Http\Services\Admin\CoinsApplicationService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CoinsApplicationController
{

    /**
     * Description：应用列表
     * Date：2021-12-3 11:07
     * @param Request $request
     * @param CoinsApplicationService $service
     * @return HomeResource
     */
    public function list(Request $request, CoinsApplicationService $service)
    {
        $service->make($request->input());
        return $service->get();
    }

    /**
     * Description：应用详情
     * Date：2021-12-3 11:07
     * @param CoinsApplicationRequest $request
     * @param CoinsApplicationService $service
     * @return HomeResource
     */
    public function detail(CoinsApplicationRequest $request, CoinsApplicationService $service)
    {
        return $service->detail($request->input('id'));

    }

    /**
     * Description：创建应用
     * Date：2021-12-3 11:07
     * @param CoinsApplicationCreateRequest $request
     * @param CoinsApplicationService $service
     * @return HomeResource
     */
    public function create(CoinsApplicationCreateRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->create($request->input());
        });
    }

    /**
     * Description：修改应用
     * Date：2021-12-8 09:20
     * @param CoinsApplicationUpdateRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function update(CoinsApplicationUpdateRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->update($request->input());
        });

    }

    /**
     * Description：应用开启
     * Date：2021-12-3 11:07
     * @param CoinsApplicationRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function open(CoinsApplicationRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->open($request->input('id'));
        });
    }

    /**
     * Description：应用关闭
     * Date：2021-12-3 11:07
     * @param CoinsApplicationRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function close(CoinsApplicationRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->close($request->input('id'));
        });
    }


    /**
     * Description：设置是否支持手动增加红包
     * @param CoinsApplicationUpdateManualRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function is_manual(CoinsApplicationUpdateManualRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->is_manual($request->input());
        });

    }

    /**
     * Description：设置是否支持红包抵扣
     * @param CoinsApplicationUpdateDeductRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function is_deduct(CoinsApplicationUpdateDeductRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->is_deduct($request->input());
        });

    }

    /**
     * Description：设置验证模式
     * @param CoinsApplicationUpdateTypeRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function verify_type(CoinsApplicationUpdateTypeRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->verify_type($request->input());
        });

    }

    /**
     * Description：设置结算规则
     * @param CoinsApplicationUpdateRuleRequest $request
     * @param CoinsApplicationService $service
     * @return mixed
     */
    public function rule_update(CoinsApplicationUpdateRuleRequest $request, CoinsApplicationService $service)
    {
        return DB::transaction(function () use ($request, $service) {
            return $service->rule_update($request->input());
        });

    }

}
